<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/24
 * Time: 9:41
 * 优惠券列表
 */

namespace App\Http\Controllers\Api\Passenger;


use App\Http\Controllers\Controller;
use App\Services\CouponService;
use Illuminate\Http\Request;

class CouponController extends Controller
{
    /**
     * 列表
     */
    public function getList(Request $request , CouponService $service )
    {
        $name =(string) $request->get('name','');
        return $this->sendJson($service->get_list($name));
    }

    /**
     * 领取优惠券
     */
    public function collect_coupons(Request $request , CouponService $service )
    {
        $user_id = (int) $request->post('user_id');
        $coupon_id = (int)$request->post('coupon_id');
        if(!$user_id)return_bob('用户不存在');
        if(!$coupon_id)return_bob('优惠券ID必传');
        if($service->grantActivityCoupon($user_id,$coupon_id)){
            return $this->sendJson('ok');
        }
        return $this->sendError('error');
    }
}